package com.zjg.vue_cms.user.controller;

import cn.hutool.json.JSONObject;
import com.smdt.tools.log.LogData;
import com.smdt.tools.log.annotation.AopLog;
import com.zjg.vue_cms.common.Result;
import com.zjg.vue_cms.user.dao.TbUserMapper;
import com.zjg.vue_cms.user.dto.UserInfo;
import com.zjg.vue_cms.user.log.UserLogHander;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author guass
 * @date 2022年04月16日 16:08
 */
@CrossOrigin
@RestController
@Slf4j
@RequestMapping("/user")
@AopLog(logOnErr = true, tag = "user", handler = UserLogHander.class, stackTraceOnErr = true)
public class UserController {

    @Resource
    private TbUserMapper tbUserMapper;

    @GetMapping("/{id}")
    public Result<UserInfo> getUserInfo(@PathVariable String id, @RequestBody JSONObject jsonParam, @RequestParam Map<String, String> params) {

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();


        UserInfo userInfo = new UserInfo();

        LogData.step("1. 第一步执行完成");
        //......
        LogData.step("2. 第二步执行完成");
        //.....
        LogData.step("3. service的方法执行完成");

//        int i = 10 / 0;

        System.out.println("userMapper.selectById(1L) = " + tbUserMapper.selectByPrimaryKey(1));

        log.info("guass {}",authentication.getPrincipal());
        log.info("guass {}",authentication.getDetails());

        return Result.success(userInfo);
    }
}
